package com.honeycomb.action.web;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.aspectj.weaver.Dump.INode;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import com.honeycomb.action.BaseAjaxAction;
import com.honeycomb.service.ITagService;
import com.honeycomb.utils.HoneyCombColumnIndicator;
import com.honeycomb.utils.SystemConstants;
import com.honeycomb.vo.BaseVO;
import com.honeycomb.vo.ResultDto;
import com.honeycomb.vo.TaginfoVO;

/**
 * 
 * @author ZhongJiang
 * 
 * @function AJAX获取标签列表
 * 
 * @return json
 *
 */	


public class AjaxQueryHotTagListAction extends BaseAjaxAction {

	private ITagService iTagService;
	
	public ITagService getiTagService() {
		return iTagService;
	}
	public void setiTagService(ITagService iTagService) {
		this.iTagService = iTagService;
	}

	@Override
	protected JSONObject doRequest(HttpServletRequest request,
			HttpServletResponse response, HttpSession session) throws Exception {
		logger.info("-----------------AjaxQueryHotTagListAction----------------------");
		ResultDto<TaginfoVO> resultDtoQueryHotTagList = null;
		List<TaginfoVO> tagInfoVOList = null;
		TaginfoVO tagInfoVO = null;
		
		JSONObject jo = new JSONObject();
		JSONArray ja = new JSONArray();
		JSONObject joo = null;
		
		try {
			resultDtoQueryHotTagList = this.iTagService.findHotTagList();
			if(resultDtoQueryHotTagList.isSuccess()) {
				tagInfoVOList = resultDtoQueryHotTagList.getResultList();
				for(int i=0;i<tagInfoVOList.size();i++) {
					tagInfoVO = tagInfoVOList.get(i);
					joo = new JSONObject();
					joo.put("tagId", tagInfoVO.getTagId());
					joo.put("tagName", tagInfoVO.getTagName());
					joo.put("tagCnt", tagInfoVO.getTagCnt());
					joo.put("tagSeq", tagInfoVO.getTagSeq());
					ja.add(joo);
				}
				jo.put("data", ja);
				jo.put("result", SystemConstants.AJAX_SUCCESS);
			}else {
				jo.put("result", SystemConstants.AJAX_FAILED_ALERT);
			}
			return jo;
		} catch (Exception e) {
			e.printStackTrace();
			jo.put("result", SystemConstants.AJAX_FAILED_ALERT);
			return jo;
		}
	}

}








